Completed
Push — master ( 3b8b0c...578b04 )
by Michael
02:39
created

NodeForm.js ➔ show   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 16
rs 9.8

1 Function

Rating   Name   Duplication   Size   Complexity  
A NodeForm.js ➔ ... ➔ ??? 0 7 1
1
class NodeForm {
2
    /**
3
     * Show this form in a jQueryUI dialog
4
     *
5
     * @return {void}
6
     */
7
    show() {
8
        this.hasBeenOpened = true;
9
        this.$form.dialog({
10
            title: this.name,
11
            width: 800,
12
            appendTo: '.dokuwiki',
13
            modal: true,
14
            open: () => {
15
                const TIMEOUT_TO_LOOK_SMOOTH = 50;
16
                window.setTimeout(() => {
17
                    // hack to ensure this dialog is in front of other open dialogs, e.g. the footnote dialog.
18
                    this.$form.dialog('moveToTop');
19
                }, TIMEOUT_TO_LOOK_SMOOTH);
20
            },
21
        });
22
    }
23
24
    /**
25
     * Hide this form/dialog
26
     *
27
     * @return {void}
28
     */
29
    hide() {
30
        if (this.hasBeenOpened) {
31
            this.$form.dialog('close');
32
        }
33
    }
34
35
    /**
36
     * Bind a callback to an event on the form
37
     *
38
     * @param {string} eventName name of the event, can contain namespaces (e.g. click.myPlugin )
39
     * @param {function} callback the handler function to be attached to the event
40
     *
41
     * @return {void}
42
     */
43
    on(eventName, callback) {
44
        this.$form.on(eventName, callback);
45
    }
46
47
    /**
48
     * Remove a handler from an event
49
     *
50
     * @param {string} eventName name of the event, can contain namespaces (e.g. click.myPlugin )
51
     *
52
     * @return {void}
53
     */
54
    off(eventName) {
55
        this.$form.off(eventName);
56
    }
57
58
    destroy() {
59
        this.$form.remove();
60
    }
61
}
62
63
export default NodeForm;
64